package com.example.service.impl;

import com.example.mapper.TbBookBaseMapper;
import com.example.mapper.TbBookMapper;
import com.example.pojo.TbBook;
import com.example.pojo.TbBookBase;
import com.example.service.TbBookBaseService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/**
 * Author:20201002983_郑雨蓓
 * Date: 2022/12/15
 * Description:
 */
@Service
@Transactional(propagation = Propagation.REQUIRED,isolation = Isolation.DEFAULT,timeout = -1,readOnly = false,rollbackFor ={Exception.class})
public class TbBookBaseServiceImpl implements TbBookBaseService {
    @Resource
    TbBookBaseMapper tbBookbaseMapper;
    @Resource
    TbBookMapper tbBookMapper;//售价

    @Transactional(propagation = Propagation.NOT_SUPPORTED,isolation = Isolation.DEFAULT,timeout = -1,readOnly = true,rollbackFor ={Exception.class})
    @Override
    public List<TbBookBase> list() {
        return tbBookbaseMapper.list();
    }

    @Override
    public TbBookBase selectById(Long bookId) {
        return tbBookbaseMapper.selectById(bookId);
    }

    @Override
    public List<TbBookBase> selectByCategoryId(Long cid) {
        return tbBookbaseMapper.selectByCategoryId(cid);
    }

    @Override
    public List<TbBookBase> selectByName(String bookName) {
        return tbBookbaseMapper.selectByName(bookName);
    }

    @Override
    public List<TbBookBase> selectByWriter(String writerName) {
        return tbBookbaseMapper.selectByWriter(writerName);
    }

    @Override
    public List<TbBookBase> selectByMulCon(TbBookBase tbBook) {
        return tbBookbaseMapper.selectByMulCon(tbBook);
    }

    @Override
    public int add(TbBookBase tbBook) {
//        TbBook tbBookTemp = tbBookMapper.selectById(tbBook.getBookId());
//        tbBook.setSellingPrice(tbBookTemp.getSellingPrice());//获得售价
//        tbBook.setBookId(tbBookTemp.getBookId());
        return tbBookbaseMapper.add(tbBook);
    }

    @Override
    public int add2(TbBookBase tbBook) {
        return tbBookbaseMapper.add2(tbBook);
    }

    @Override
    public int update(TbBookBase tbBook) {
        return tbBookbaseMapper.update(tbBook);
    }

    @Override
    public int updateSellingPrice(Integer sellingPrice, Long id) {
        return tbBookbaseMapper.updateSellingPrice(sellingPrice, id);
    }

}
